home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Pascal / Applications / MakeFat 1.0 / PNL Libraries / MyRequiredEventSupport.p < prev    next >
Encoding:
Text File  |  1995-11-10  |  4.6 KB  |  148 lines  |  [TEXT/CWIE]

  1. unit MyRequiredEventSupport;
  2.  
  3. interface
  4.  
  5.     uses
  6.         AppleEvents, MyTypes;
  7.  
  8.     var
  9.         required_event_with_option: boolean;
  10.         required_event_with_control: boolean;
  11.  
  12.     type
  13.         DocProc = function (var fs:FSSpec): OSErr;
  14.         NoDocProc = function: OSErr;
  15.     
  16.     procedure InitAppleEvents (DoOpenApplication:NoDocProc; DoOpenDocuments:DocProc; DoPrintDocuments: DocProc; DoQuitApplication: NoDocProc);
  17.  
  18. implementation
  19.  
  20.     uses
  21.         MyAEUtils;
  22.         
  23.     var
  24.         gDoOpenApplication: NoDocProc;
  25.         gDoOpenDocuments: DocProc;
  26.         gDoPrintDocuments: DocProc;
  27.         gDoQuitApplication: NoDocProc;
  28.  
  29.     procedure GetModifiers(var event: AppleEvent);
  30.         var
  31.             err, junk: OSErr;
  32.             psn: ProcessSerialNumber;
  33.             pi: ProcessInfoRec;
  34.             dummy: Boolean;
  35.             er: EventRecord;
  36.             keywd: AEKeyword;
  37.             actualSize: Size;
  38.     begin
  39.     { check if the event comes from the finder and honour the option/control keys }
  40.         required_event_with_control := false;
  41.         required_event_with_option := false;
  42.         err := AEGetAttributePtr(event, keyAddressAttr, keyProcessSerialNumber, keywd, @psn, SizeOf(psn), actualSize);
  43.         if err = noErr then begin
  44.             pi.processInfoLength := sizeof(ProcessInfoRec);
  45.             pi.processName := nil;
  46.             pi.processAppSpec := nil;
  47.             err := GetProcessInformation(psn, pi);
  48.         end;
  49.         if (err = noErr) & (pi.processSignature = 'MACS') then begin
  50.             dummy := OSEventAvail(everyEvent, er);
  51.             required_event_with_option := BAND(er.modifiers, optionKey) <> 0;
  52.             required_event_with_control := BAND(er.modifiers, controlKey) <> 0;
  53.         end;
  54.         junk := GetBooleanFromAERecord(event, keyOdocOption, required_event_with_option);
  55.         junk := GetBooleanFromAERecord(event, keyOdocControl, required_event_with_control);
  56.  
  57.     end;
  58.     
  59.     function HandleNoDocs (var event, reply: AppleEvent; Doit:NoDocProc): OSErr;
  60.         var
  61.             err: OSErr;
  62.     begin
  63.         reply := reply; { UNUSED! }
  64.         GetModifiers(event);
  65.         err := GotRequiredParams(event);
  66.         if err = noErr then begin
  67.             err := Doit;
  68.         end;
  69.         HandleNoDocs := err;
  70.     end;
  71.  
  72.     function HandleDocs (var event, reply: AppleEvent; Doit:DocProc): OSErr;
  73.         var
  74.             myFSS: FSSpec;
  75.             docList: AEDescList;
  76.             index, itemsInList: longint;
  77.             typeCode: descType;
  78.             err, oerr, junk: OSErr;
  79.             keywd: AEKeyword;
  80.             actualSize: Size;
  81.     begin
  82.         reply := reply; { UNUSED! }
  83.         GetModifiers(event);
  84.         err := AEGetParamDesc(event, keyDirectObject, typeAEList, docList);
  85.         if err = noErr then begin
  86.             junk := GotRequiredParams(event);
  87. (* now get each alias from the list (as an FSSSpec) and open the associated file. *)
  88.             err := AECountItems(docList, itemsInList);
  89.             for index := 1 to itemsInList do begin
  90.                 oerr := AEGetNthPtr(docList, index, typeFSS, keywd, typeCode, @myFSS, sizeof(myFSS), actualSize);
  91. (* coercion does alias->fsspec *)
  92.                 if oerr = noErr then begin
  93.                     oerr := Doit(myFSS);
  94.                 end;
  95.             end;
  96.             junk := AEDisposeDesc(docList);
  97.         end;
  98.         HandleDocs := err;
  99.     end;
  100.  
  101.     function HandleOpenApplication(var event, reply: AppleEvent; ignored: longint): OSErr;
  102.     begin
  103.         ignored := ignored; { UNUSED! }
  104.         HandleOpenApplication := HandleNoDocs(event, reply, gDoOpenApplication);
  105.     end;
  106.  
  107.     function HandleOpenDocuments (var event, reply: AppleEvent; ignored: longint): OSErr;
  108.     begin
  109.         ignored := ignored; { UNUSED! }
  110.         HandleOpenDocuments := HandleDocs(event, reply, gDoOpenDocuments);
  111.     end;
  112.     
  113.     function HandlePrintDocuments(var event, reply: AppleEvent; ignored: longint): OSErr;
  114.     begin
  115.         ignored := ignored; { UNUSED! }
  116.         HandlePrintDocuments := HandleDocs(event, reply, gDoPrintDocuments);
  117.     end;
  118.     
  119.     function HandleQuitApplication(var event, reply: AppleEvent; ignored: longint): OSErr;
  120.     begin
  121.         ignored := ignored; { UNUSED! }
  122.         HandleQuitApplication := HandleNoDocs(event, reply, gDoQuitApplication);
  123.     end;
  124.  
  125.     procedure InitAppleEvents (DoOpenApplication:NoDocProc; DoOpenDocuments:DocProc; DoPrintDocuments: DocProc; DoQuitApplication: NoDocProc);
  126.         var
  127.             junk: OSErr;
  128.     begin
  129.         gDoOpenApplication := DoOpenApplication;
  130.         gDoOpenDocuments := DoOpenDocuments;
  131.         gDoPrintDocuments := DoPrintDocuments;
  132.         gDoQuitApplication := DoQuitApplication;
  133.         if (@gDoOpenApplication <> nil) then begin
  134.             junk := AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, NewAEEventHandlerProc(@HandleOpenApplication), 0, false);
  135.         end;
  136.         if (@gDoOpenDocuments <> nil) then begin
  137.             junk := AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, NewAEEventHandlerProc(@HandleOpenDocuments), 0, false);
  138.         end;
  139.         if (@gDoPrintDocuments <> nil) then begin
  140.             junk := AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, NewAEEventHandlerProc(@HandlePrintDocuments), 0, false);
  141.         end;
  142.         if (@gDoQuitApplication <> nil) then begin
  143.             junk := AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, NewAEEventHandlerProc(@HandleQuitApplication), 0, false);
  144.         end;
  145.     end;
  146.  
  147. end.
  148.